Tags: graph representations, lecture-10
Let \(A\) be the adjacency matrix representing a directed graph with \(n\) nodes. What is the greatest possible sum of any row of \(A\)?
\(n\).
Row \(u\) of \(A\) has a one for each edge leaving \(u\), so its sum is \(u\)'s out-degree. A directed graph may have self-loops, so \(u\) can have an edge to all \(n\) nodes, including itself, and the row can be all ones.
Tags: graph representations, lecture-10
Let \(A\) be the adjacency matrix representing an undirected graph with \(n\) nodes. What is the greatest possible sum of any row of \(A\)?
\(n - 1\).
The sum of row \(i\) is the degree of node \(i\). Since an undirected graph has no self-loops, a node can be adjacent to at most the other \(n - 1\) nodes.
Tags: graph representations, lecture-10
An isolated node in an undirected graph is a node that has no neighbors.
Suppose a graph \(G = (V, E)\) is represented using an adjacency matrix. What is the best possible worst-case time complexity of an efficient algorithm for computing the number of isolated nodes in the graph? State your answer as a function of \(|V|\) and \(|E|\) using asymptotic notation.
\(\Theta(V^2)\).
A node \(u\) is isolated exactly when row \(u\) of the adjacency matrix is all zeros. To check that, we have to look at the entries of that row until we find a one; if the node is isolated, there is no one to find, so we look at all \(|V|\) entries. Doing this for every node takes \(|V| \times \Theta(V) = \Theta(V^2)\) time in the worst case.
We can't do better. In the worst case, e.g., a graph with no edges at all, every node is isolated, and to be sure of that, an algorithm has to read every entry of the matrix (or, by symmetry, every entry on one side of the diagonal, which is still \(\Theta(V^2)\) entries): any entry it skips could be a one, which would make two nodes not isolated. Notice that the answer doesn't depend on \(|E|\): with an adjacency matrix, scanning a row takes \(\Theta(V)\) time no matter how many edges there are.
Tags: graph representations, lecture-10
An “isolated node” in a graph is a node that has no edges attached to it.
What is the worst case time complexity of an efficient algorithm that checks to see if a graph \(G = (V, E)\) has an isolated node? You should assume that the graph is represented as an adjacency list.
\(\Theta(V)\).
A node is isolated exactly when its adjacency list is empty, which we can check in \(\Theta(1)\) time per node, so checking every node takes \(\Theta(V)\) time. In the worst case (no node is isolated), we have to check them all.
Tags: graph representations, lecture-10
Let \(A\) be the adjacency matrix of the graph shown below:

Let \(\vec{a}^{(1)}\) be the first row of \(A\) and \(\vec{a}^{(2)}\) be the second row of \(A\). What is \(\vec{a}^{(1)} \cdot \vec{a}^{(2)}\)? That is, what is the dot product between the first row of \(A\) and the second row of \(A\)? Your answer should be in the form of a number.
It may help to recall that the dot product between vectors \(\vec x = (x_1, \ldots, x_d)^T\) and \(\vec y = (y_1, \ldots, y_d)^T\) is equal to \(x_1 y_1 + x_2 y_2 + \ldots + x_d y_d\).
4.
Each entry of the dot product is 1 exactly when a node is a neighbor of both node 1 and node 2, so the dot product counts their common neighbors. Node 1's neighbors are the top node, the two nodes on the upper left and upper right, the node on the right, and the node on the lower left; node 2 is adjacent to all of these except the upper-left node, so there are 4 common neighbors.
No 🌶️ problems in this topic.